// 示例 1：

// 输入：tokens = ["2", "1", "+", "3", "*"]
// 输出：9
// 解释：该算式转化为常见的中缀算术表达式为：((2 + 1) * 3) = 9
// 示例 2：

// 输入：tokens = ["4", "13", "5", "/", "+"]
// 输出：6
// 解释：该算式转化为常见的中缀算术表达式为：(4 + (13 / 5)) = 6

tokens = ["2", "1", "+", "3", "*"]

var evalRPN = function (tokens) {
    let stack = []
    for (let str of tokens) {
        if (str === '+') {
            let b = stack.pop()
            let a = stack.pop()
            stack.push(a + b)
        } else if (str === '-') {
            let b = stack.pop()
            let a = stack.pop()
            stack.push(a - b)
        } else if (str === '*') {
            let b = stack.pop()
            let a = stack.pop()
            stack.push(a * b)
        } else if (str === '/') {
            let b = stack.pop()
            let a = stack.pop()
            stack.push(parseInt(a / b))
        } else {
            stack.push(parseInt(str))
        }
    }
    return stack[0]
};

console.log(evalRPN(tokens));
